package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.data.ContentInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;

/**
 * Created by windo on 16/7/13.
 */
public class ContentDetailTask extends CouponHttpBaseTask {
    private String mClubId;

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject jsonObject = response.getBody();
        ContentInfo info = null;
        if (jsonObject != null) {
            info = JSON.parseObject(jsonObject.getString("data"), ContentInfo.class);
        }
        notifyTaskCompleted(TaskResultCode.SUCCESS, info);
    }

    public ContentDetailTask(String contentId) {
        super();
        mClubId = contentId;
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT) {
            CouponHttpRequest request = new CouponHttpRequest();
            request.setApiNo(ApiNo.CONTENTDETAIL);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("contentId", mClubId);
            request.setData(jsonObject.toString());
            addRequest(request);
        }
    }
}
